const express = require('express')
const router = express.Router()
const db = require('../../connection/Connection')
const jwt = require('jsonwebtoken')
const SECRET = 'asdfta219*&%^jWJSHFJ'


router.post('/deleteStation', async (req, res) => {
    //token
    const result = jwt.verify(req.body.token, SECRET)
    let sql = 'select departmentId from user_role where username = ?'
    db.base(sql, result.username, response => {
        //验证成功
        // console.log('response=',response)
        console.log('responselength=',response.length)
        if (response.length > 0 && response[0].departmentId === 999){
            //删除岗位表
            let sql = 'delete from station where station_id = ?  '
            db.base(sql, req.body.station_id, () => {
                res.json({
                    'code': 200,
                    'result': 'true',
                    'type': 'delete_success',
                    'content': '成功删除岗位',
                })
            })
        }
        else {
            res.json({
                'code': 403,
                'result': 'false',
                'type': 'non_access',
                'content': '无权限'
            })
        }
    })
})

module.exports = router
